﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrderApp2
{
   public  class  Order
    {
        //订单号
        public int orderID; 
        //顾客会员号
        public int cusID;
        //订单生成时间
        public DateTime orderDate;
        //订单配送地址
        public string shippingAddress;
        //订单明细
        public List<OrderItem> orderItems = new List<OrderItem>();

        public Order(int order_id,int cus_id,DateTime order_date,string order_shippingaddress)
        {
            this.orderID = order_id;
            this.cusID = cus_id;
            this.orderDate = order_date;
            this.shippingAddress = order_shippingaddress;
        }
        //求订单总价
        public double orderPrice
        {
            get
            {
                double sum = 0;
                foreach (OrderItem item in orderItems)
                    sum += item.item_priceInTotal;
                return sum;

            }
        }

        //订单是否重复
        public override bool Equals(object obj)
        {
            Order order = obj as Order;
            if (order == null)
                return false;
            else
            {
                return order.orderID == orderID;

            }
        }
        //打印订单页面
        public override string ToString()
        {
            return
                $"\n订单号：{orderID}"
            + $"       顾客会员号：{cusID}\n"
            + $"订单生成时间：{orderDate}\n"
            + $"总价：{orderPrice}\n"
            + $"订单配送地址：{shippingAddress.ToString()}\n"
            + $"-----------------------------------------\n"
            + $"商品名称       单价         数量     金额\n"
            + $"-----------------------------------------\n";

        }

        public void order_addItems(OrderItem order_Item_toAdd)
        {
            orderItems.Add(order_Item_toAdd);
        }

    }
}
